home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / Programs / Ipswitch.IMail.Server.Pro.8.0.Winall / IMail8ec.exe / data1.cab / Web_Standard / listboxcontrol.cgi < prev    next >
Encoding:
Text File  |  2003-05-07  |  5.8 KB  |  220 lines

  1.   function doButtonAction(form, buttonAction)
  2.   {
  3.     // This function is designed to respond
  4.     // to the various button actions.  This
  5.     // function is launched after a button
  6.     // is clicked.
  7.  
  8.  
  9.       if (buttonAction == "<!--IMAIL.SaveButton-->"
  10.           || buttonAction == "<!--IMAIL.UpdateButton-->")
  11.     {
  12.         // Construct the list that will be submitted in the POST
  13.           for(var x=0; x < form.theListEntry.options.length; x++)
  14.           {
  15.             if(form.theList.value=="")
  16.             {
  17.               form.theList.value += form.theListEntry.options[x].text;
  18.             }
  19.             else
  20.             {
  21.               form.theList.value += delimiter + form.theListEntry.options[x].text;
  22.             }
  23.           }
  24.  
  25.       form.imail_action.value = buttonAction;
  26.       form.submit();
  27.     }
  28.       else if (buttonAction == "<!--IMAIL.AddButton-->")
  29.       {
  30.         // Check to see if the entry is not already in the list
  31.       if(isEntryInList(form, buttonAction) == 0)
  32.           {
  33.             resetListBoxForm(form);
  34.             return;
  35.           }
  36.  
  37.       // Check to see if the entry's value is NULL
  38.       if(isEntryEmpty(form) == 0)
  39.       {
  40.         resetListBoxForm(form);
  41.             return;
  42.       }
  43.         
  44.           // Add the entry into the list
  45.           addListOption(form.theListEntry.options.length, form.entry.value, form.theListEntry);
  46.  
  47.           resetListBoxForm(form);
  48.       }
  49.       else if (buttonAction == "Edit")
  50.       {
  51.         if (form.theListEntry.selectedIndex == -1)
  52.         {
  53.             alert("Please select an entry to edit from the "+listName+".");
  54.             form.theListEntry.focus();
  55.             return;
  56.           }
  57.  
  58.           // Check to see if the entry is not already in the list
  59.       if(isEntryInList(form, buttonAction) == 0)
  60.           {
  61.             form.entry.focus();
  62.             return;
  63.           }
  64.  
  65.       // Check to see if the entry's value is NULL
  66.       if(isEntryEmpty(form) == 0)
  67.       {
  68.         form.entry.focus();
  69.             return;
  70.       }
  71.  
  72.           // Edit the specified entry in the list
  73.         editListOption(form.theListEntry.selectedIndex, form.entry.value, form.theListEntry);
  74.  
  75.           // Reset the list to its inital condtion
  76.       resetListBoxForm(form);
  77.       }
  78.       else if (buttonAction == "<!--IMAIL.RemoveButton-->")
  79.       {
  80.         // Remove the specified entry from the list
  81.           removeListOption(form.theListEntry.selectedIndex, form.theListEntry);
  82.         
  83.         // Reset the list to its inital condtion
  84.       resetListBoxForm(form);
  85.       }
  86.   }
  87.  
  88.     function addListOption(optValue, optText, listObj)
  89.     {
  90.     // Add an option to the list
  91.       listObj.options[listObj.length] = new Option (optText,optValue);
  92.     }
  93.  
  94.     function editListOption(optIndex, optText, listObj)
  95.     {
  96.     // Edit the selected option in the list
  97.       listObj.options[optIndex].text = optText;
  98.     }
  99.  
  100.     function removeListOption(optIndex, listObj)
  101.     {
  102.     // Remove the selected option from the list
  103.       listObj.options[optIndex] = null;
  104.     }
  105.  
  106.     function isEntryInList(form, buttonAction)
  107.     {
  108.       // Check to see if value in the "entry" textbox is already in the list
  109.       for(var x=0; x < form.theListEntry.options.length; x++)
  110.       {
  111.         if(form.theListEntry.options[x].text==form.entry.value)
  112.           {
  113.         if (buttonAction=="<!--IMAIL.AddButton-->")
  114.         {
  115.               alert("The "+entryName+", \""+form.entry.value+"\" is already in the "+listName+"; therefore, the "+entryName+" will not be added to the "+listName+".");
  116.         }
  117.         else if (buttonAction=="Edit")
  118.         {
  119.           alert("The "+entryName+", \""+form.entry.value+"\" is already in the "+listName+"; therefore, your changes will not be saved to the "+listName+". \n\nNote: Use the text field, on this form, to make modifications to the selected entry.");
  120.         }
  121.             return 0;
  122.           }
  123.       }
  124.       return 1;
  125.     }
  126.  
  127.   function isEntryEmpty(form)
  128.   {
  129.     // Check to see if the value in the "entry" textbox is NULL
  130.     if(form.entry.value.length <= 0)
  131.     {
  132.       alert("Please enter a valid "+entryName+" in the text field.")
  133.       return 0;
  134.     }
  135.     return 1;
  136.   }
  137.  
  138.     function changeModeTo(form, mode)
  139.     {
  140.     // This function changes the mode for the list box.  The two modes
  141.     // are "Edit" and "Add."  If the list box is in "Edit" mode, the add, edit,
  142.     // and remove buttons should be enabled.  It the list box is in "Add" mode,
  143.     // only the add button should be enabled.
  144.  
  145.       if (mode=="Edit")
  146.       {
  147.           var i = form.theListEntry.selectedIndex;
  148.           if(i != -1)
  149.           {
  150.             form.editBtn.disabled = 0;
  151.             form.removeBtn.disabled = 0;
  152.  
  153.             form.entry.value = form.theListEntry.options[i].text;
  154.             form.entry.focus();
  155.           }
  156.     }
  157.  
  158.       if (mode=="Add")
  159.       {
  160.         form.editBtn.disabled = 1;
  161.           form.removeBtn.disabled = 1;
  162.           form.addBtn.disabled = 0;
  163.         
  164.           form.theListEntry.selectedIndex = -1;
  165.           form.entry.focus();
  166.       }
  167.     }
  168.  
  169.     function resetListBoxForm(form)
  170.     {
  171.     // This function resets the list box
  172.     // back to its initial condition
  173.  
  174.  
  175.       // Clear the entry textbox
  176.       form.entry.value = "";
  177.  
  178.       // Deselect the entry in the list box
  179.       form.theListEntry.selectedIndex = -1;
  180.  
  181.       // Change to "add" mode
  182.       changeModeTo(form, "Add")
  183.       
  184.     }
  185.  
  186.   function disableTextbox(form)
  187.   {
  188.     // Disable the text box if
  189.     // the "Delete" option or the
  190.     // "Insert X-header" option
  191.     // is selected.
  192.  
  193.     var mode;
  194.     var color;
  195.  
  196.     i = form.actionListEntry.selectedIndex;
  197.     if(form.actionListEntry.options[i].value == 0 || form.actionListEntry.options[i].value == 2)
  198.     {
  199.       mode = 1;
  200.       color = "#E2E2E2";
  201.       form.actionAddress.value = "";
  202.     }
  203.     else
  204.     {
  205.       mode = 0;
  206.       color = "#FFFFFF";
  207.       
  208.       // If there is no address currently in
  209.       // in the "Address" field, use the default
  210.       // value, which is "root-bulk"
  211.       if(form.actionAddress.value.length==0)
  212.       {
  213.         form.actionAddress.value = "root-bulk";
  214.       }
  215.     }
  216.  
  217.     form.actionAddress.disabled = mode;
  218.       form.actionAddress.style.background = color;
  219.     
  220.   }